package com.sky.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.sky.constant.AutoFillConstant;
import com.sky.context.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("开始插入填充...");
        this.strictInsertFill(metaObject, AutoFillConstant.CREATE_TIME, LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, AutoFillConstant.UPDATE_TIME, LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject,AutoFillConstant.CREATE_USER,Long.class, BaseContext.getCurrentEmpId());
        this.strictInsertFill(metaObject,AutoFillConstant.UPDATE_USER,Long.class,BaseContext.getCurrentEmpId());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("开始更新填充...");
        this.strictUpdateFill(metaObject,AutoFillConstant.UPDATE_TIME,LocalDateTime.class,LocalDateTime.now());
        this.strictUpdateFill(metaObject,AutoFillConstant.UPDATE_USER,Long.class,BaseContext.getCurrentEmpId());

    }
}
